﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IPC.Communication.Framework.Core.IMessage
{
    public class MelsecA1EBinaryMessage : INetMessage
    {
        public int ProtocolHeadBytesLength
        {
            get
            {
                return 2;
            }
        }

        public byte[] HeadBytes
        {
            get;
            set;
        }

        public byte[] ContentBytes
        {
            get;
            set;
        }

        public byte[] SendBytes
        {
            get;
            set;
        }

        public int GetContentLengthByHeadBytes()
        {
            bool flag = this.HeadBytes[1] == 91;
            int result;
            if (flag)
            {
                result = 2;
            }
            else
            {
                bool flag2 = this.HeadBytes[1] == 0;
                if (flag2)
                {
                    switch (this.HeadBytes[0])
                    {
                        case 128:
                            result = (int)((this.SendBytes[10] != 0) ? ((this.SendBytes[10] + 1) / 2) : 128);
                            break;
                        case 129:
                            result = (int)(this.SendBytes[10] * 2);
                            break;
                        case 130:
                        case 131:
                            result = 0;
                            break;
                        default:
                            result = 0;
                            break;
                    }
                }
                else
                {
                    result = 0;
                }
            }
            return result;
        }

        public bool CheckHeadBytesLegal(byte[] token)
        {
            bool flag = this.HeadBytes != null;
            return flag && this.HeadBytes[0] - this.SendBytes[0] == 128;
        }

        public int GetHeadBytesIdentity()
        {
            return 0;
        }
    }
}
